home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 7 / Apprentice-Release7.iso / Source Code / C / Applications / Moscow ML 1.42 / lib / Time.sig < prev    next >
Encoding:
Text File  |  1997-08-18  |  3.6 KB  |  101 lines  |  [TEXT/Moml]

  1. (* Time -- SML Basis Library *)
  2.  
  3. eqtype time
  4.  
  5. exception Time
  6.  
  7. val zeroTime : time
  8. val now      : unit -> time
  9.  
  10. val toSeconds        : time -> int
  11. val toMilliseconds   : time -> int
  12. val toMicroseconds   : time -> int
  13. val fromSeconds      : int -> time
  14. val fromMilliseconds : int -> time
  15. val fromMicroseconds : int -> time
  16.  
  17. val fromReal : real -> time
  18. val toReal   : time -> real
  19.  
  20. val toString   : time -> string    (* rounded to millisecond precision *)
  21. val fmt        : int -> time -> string
  22. val fromString : string -> time option
  23. val scan       : (char, 'a) StringCvt.reader -> (time, 'a) StringCvt.reader
  24.  
  25. val +  : time * time -> time
  26. val -  : time * time -> time
  27. val <  : time * time -> bool
  28. val <= : time * time -> bool
  29. val >  : time * time -> bool
  30. val >= : time * time -> bool
  31.  
  32. val compare : time * time -> order
  33.  
  34. (* Values of type [time] represent durations as well as absolute points 
  35.    in time (which can be thought of as durations since some time zero).
  36.  
  37.    [zeroTime] represents the 0-second duration, and the origin of time, 
  38.    so zeroTime + t = t + zeroTime = t for all t.
  39.  
  40.    [now ()] returns the point in time at which the application occurs.
  41.  
  42.    [fromSeconds s] returns the time value corresponding to s seconds.  
  43.    Raises Time if s < 0.
  44.  
  45.    [fromMilliseconds ms] returns the time value corresponding to ms
  46.    milliseconds.  Raises Time if ms < 0.
  47.  
  48.    [fromMicroseconds us] returns the time value corresponding to us
  49.    microseconds.  Raises Time if us < 0.
  50.  
  51.    [toSeconds t] returns the number of seconds represented by t,
  52.    truncated.  Raises Overflow if that number is not representable as
  53.    an int.
  54.  
  55.    [toMilliseconds t] returns the number of milliseconds
  56.    represented by t, truncated.  Raises Overflow if that number is not
  57.    representable as an int.
  58.  
  59.    [toMicroseconds t] returns the number of microseconds
  60.    represented by t, truncated.  Raises Overflow if t that number is
  61.    not representable as an int.
  62.  
  63.    [realToTime r] converts a real to a time value representing that
  64.    many seconds.  Raises Time if r < 0 or if r is not representable
  65.    as a time value.  It holds that realToTime 0.0 = zeroTime.  
  66.  
  67.    [timeToReal t] converts a time the number of seconds it represents;
  68.    hence realToTime and timeToReal are inverses of each other when 
  69.    defined.  Raises Overflow if t is not representable as a real.
  70.  
  71.    [fmt n t] returns as a string the number of seconds represented by
  72.    t, rounded to n decimal digits.  If n <= 0, then no decimal digits
  73.    are reported. 
  74.  
  75.    [toString t] returns as a string the number of seconds represented
  76.    by t, rounded to 3 decimal digits.  Equivalent to (fmt 3 t).  
  77.  
  78.    [fromString s] returns SOME t where t is the time value represented
  79.    by the string s of form [\n\t ]*([0-9]+(\.[0-9]+)?)|(\.[0-9]+); 
  80.    or returns NONE if s cannot be parsed as a time value.
  81.  
  82.    [scan getc src], where getc is a character accessor, returns SOME
  83.    (t, rest) where t is a time and rest is rest of the input, or NONE
  84.    if s cannot be parsed as a time value.
  85.  
  86.    [t1 + t2] is the sum of the times t1 and t2.  For reals r1, r2 >= 0.0, 
  87.    realToTime r1 + realToTime r2 = realToTime(Real.+(r1,r2)).  Raises 
  88.    Overflow if the result is not representable as a time value.
  89.  
  90.    [t1 - t2] is the t1 minus t2, that is, the duration from t2 to t1.
  91.    Raises Time if t1 < t2 or if the result is not representable as a
  92.    time value.  It holds that t - zeroTime = t.
  93.  
  94.    [t1 < t2] asserts that t1 is strictly before t2.  Similarly for
  95.    <=, >, >=.  It holds for reals r1, r2 >= 0.0 that
  96.        realToTime r1 < realToTime r2  iff  Real.<(r1, r2) 
  97.  
  98.    [compare(t1, t2)] returns LESS, EQUAL, or GREATER, according 
  99.    as t1 precedes, equals, or follows t2 in time.
  100. *)
  101.